package com.firewolf.fr.s009_exception;

import java.io.IOException;
import java.io.Writer;

import freemarker.core.Environment;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;

public class MyHandler implements TemplateExceptionHandler {

	public void handleTemplateException(TemplateException te, Environment env,
			Writer out) throws TemplateException {
		// 异常不做任何处理
		// 这里可以把异常处理到日志中
		System.out.println("这有一个错误");
		System.out.println("模版名：" + env.getCurrentTemplate().getName());
		System.out.println("类名：" + out.getClass().getName());
		try {
//			out.write("[ERROR: " + te.getMessage() + "]");
			out.write("");
		} catch (IOException e) {
			throw new TemplateException(
					"Failed to print error message. Cause: " + e, env);
		}
	}

}
